<template>
  <div class="app-container">
    <div class="custom_card_0" v-show="showSearch">
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        label-width="68px"
      >
        <el-form-item label="订单号" prop="bizNo">
          <el-input
            v-model="queryParams.bizNo"
            placeholder="请输入订单号"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="客户名称" prop="memberName">
          <el-input
            v-model="queryParams.memberName"
            clearable
            @1clear="handleQuery"
            style="width: 220px"
            placeholder="请输入客户名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="订单类型" prop="orderType">
          <el-select
            v-model="queryParams.orderType"
            placeholder="请选择订单类型"
            clearable
          >
            <template v-for="dict in tenantBusiness">
              <el-option
                :label="dict.busName"
                :value="dict.busId"
                :key="dict.busId"
              ></el-option>
            </template>
          </el-select>
        </el-form-item>
        <el-form-item label="账单类型" prop="billType">
          <el-select
            v-model="queryParams.billType"
            placeholder="请选择账单类型"
            clearable
          >
            <el-option label="支付流水" value="支付流水"></el-option>
            <el-option label="退款流水" value="退款流水"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="支付状态" prop="payStatus">
          <el-select v-model="queryParams.payStatus" clearable>
            <template v-for="dict in dict.type.order_payStatus">
              <el-option
                :label="dict.label"
                :value="dict.value"
                :key="dict.value"
              ></el-option>
            </template>
          </el-select>
        </el-form-item>
        <el-form-item label="支付方式" prop="payWay">
          <el-select v-model="queryParams.payWay" clearable>
            <template v-for="dict in dict.type.sys_pay_way">
              <el-option
                :label="dict.label"
                :value="dict.value"
                :key="dict.value"
              ></el-option>
            </template>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <div class="custom_card">
      <el-row :gutter="10" class="mb10">
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            :loading="exportLoading"
            @click="handleExport"
            v-hasPermi="['longOrder:record:export']"
            >导出</el-button
          >
        </el-col>
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="recordList" border>
        <el-table-column
          label="订单编号"
          align="center"
          prop="bizNo"
          min-width="200"
          show-overflow-tooltip
        />
        <el-table-column
          label="客户名称"
          align="center"
          prop="memberName"
          min-width="120"
          show-overflow-tooltip
        />
        <el-table-column
          label="订单类型"
          align="center"
          prop="orderType"
          min-width="120"
          show-overflow-tooltip
        />
        <el-table-column
          label="账单类型"
          align="center"
          prop="billType"
          min-width="120"
          show-overflow-tooltip
        />
        <el-table-column
          label="订单状态"
          align="center"
          prop="orderStatus"
          min-width="120"
          show-overflow-tooltip
        />
        <el-table-column
          label="业务类型"
          align="center"
          prop="bizType"
          min-width="120"
          show-overflow-tooltip
        />
        <el-table-column
          label="支付金额"
          align="center"
          prop="paidAmount"
          min-width="120"
          show-overflow-tooltip
        />
        <el-table-column
          label="支付状态"
          align="center"
          prop="payStatus"
          min-width="120"
          show-overflow-tooltip
        />
        <el-table-column
          label="支付方式"
          align="center"
          prop="payWay"
          min-width="120"
          show-overflow-tooltip
        />
        <el-table-column
          label="支付流水号"
          align="center"
          prop="payFlowNo"
          min-width="120"
          show-overflow-tooltip
        />
        <el-table-column
          label="创建时间"
          align="center"
          prop="createTime"
          min-width="160"
          show-overflow-tooltip
        />
        <el-table-column
          label="支付时间"
          align="center"
          prop="paidTime"
          min-width="160"
          show-overflow-tooltip
        />
        <el-table-column
          label="备注"
          align="center"
          prop="remark"
          min-width="160"
          show-overflow-tooltip
        />
        <el-table-column
          label="支付凭证"
          align="center"
          width="160"
          fixed="left"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              v-if="scope.row.url != null && scope.row.url != ''"
              @click="viewCostsVoucher(scope.row.url)"
              >查看凭证</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <el-dialog
      title="支付凭证"
      :visible.sync="showpingzheng"
      width="500px"
      destroy-on-close
      append-to-body
      @close="closeDiolog"
    >
      <el-image class="preview" :src="getImgUrl(url)" fit="contain"> </el-image>
    </el-dialog>
  </div>
</template>

<script>
import { tenantBusiness } from '@/api/car/business'
import { exportRecord, getRecord, listRecord } from '@/api/paymentRecord/record'
export default {
  name: 'Record',
  dicts: ['order_payStatus', 'sys_pay_way'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 长租账单记录表格数据
      recordList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      pingzheng: true,
      showpingzheng: false,
      url: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderType: null,
        bizNo: null,
        payWay: null,
        paidTime: null,
        payStatus: null,
        memberName: null,
        billType: '',
      },
      tenantBusiness: [],
    }
  },
  created() {
    this.getList()
    this.tenantBusinessList()
  },
  methods: {
    tenantBusinessList() {
      tenantBusiness().then((response) => {
        this.tenantBusiness = response.data
      })
    },
    closeDiolog() {
      this.pingzheng = true
    },
    viewCostsVoucher(url) {
      this.url = url
      this.showpingzheng = true
      this.pingzheng = false
    },
    /** 查询支付流水记录列表 */
    getList() {
      this.loading = true
      listRecord(this.queryParams).then((response) => {
        this.recordList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.queryParams = {
        orderType: null,
        bizNo: null,
        payWay: null,
        paidTime: null,
        payStatus: null,
        memberName: null,
        billType: '',
      }
      // this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams
      this.$modal
        .confirm('是否确认导出所有支付流水记录数据项？')
        .then(() => {
          this.exportLoading = true
          return exportRecord(queryParams)
        })
        .then((response) => {
          this.$download.name(response.msg)
          this.exportLoading = false
        })
        .catch(() => {})
    },
  },
}
</script>
